<!-- 我的单选框按钮 -->
<template>
    <label class="t-radio-wp" :class="{active: modelValue == value}">
        <div class="icon">
            <input
                type="radio"
                :name="name"
                :value="value"
                :checked="modelValue == value"
                @change="handleChange"
            />
        </div>
        <span class="label">{{ label }}</span>
    </label>
    
</template>
<script>
export default {
    model: {
        prop: 'modelValue',
        event: 'input'
    },
    props: {
        modelValue: {
            type: [String, Number],
            default: ''
        },
        value: {
            type: [String, Number],
            required: true
        },
        label: {
            type: String,
            default: ''
        },
        name: {
            type: String,
            default: 'default-radio-group'
        },
        // 是否可以点击，改变modelValue
        canclick: {
            type: Boolean,
            default: true
        }
    },
    methods: {
        handleChange(e) {
            if(!this.canclick) {
                return;
            }
            this.$emit('input', this.value);
        }
    }
};
</script>
<style scoped lang='scss'>
.t-radio-wp {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-right: 20px;
    .icon {
        position: relative;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: var(--color-3B3C3D-B0B0B0);
        &:before {
            content: '';
            position: absolute;
            inset: 1px;
            background: var(--color-FFFFFF-1E1E1E);
            border-radius: 50%;
        }
        input {
            position: relative;
            z-index: 0;
            width: 0;
            height: 0;
            opacity: 0;
        }
    }
    .label {
        color: var(--color-3B3C3D-B0B0B0);
    }
    &.active {
        .icon {
            &:before {
                inset: 7px;
            }
        }
    }
}
</style>